/**
 * 
 */
function delete_permission_manager(user_id) {
	var frm = document.main_form;
	$('#user_id').val(user_id);
	frm.submit();
}
function add_permission_manager() {
	var frm = document.main_form;
	$('#user_id').val($('#user').val());
	$('#mode').val('add');
	frm.submit();
}
function add_controller() {
	var frm = document.main_form;
	$('#mode').val('add');
	$('#name').val($('#txt_name').val());
	$('#controller_txt').val($('#txt_controller').val());
	frm.submit();
}
function edit_controller() {
	var frm = document.main_form;
	$('#mode').val('edit');
	$('#name').val($('#edit_txt_name').val());
	$('#controller_txt').val($('#edit_txt_controller').val());
	frm.submit();
}
function add_action() {
	var frm = document.main_form;
	$('#mode').val('add');
	$('#name').val($('#txt_name').val());
	$('#controller_id').val($('#cmb_controller').val());
	$('#action_txt').val($('#txt_action').val());
	frm.submit();
}
function edit_action() {
	var frm = document.main_form;
	$('#mode').val('edit');
	$('#name').val($('#edit_txt_name').val());
	$('#controller_id').val($('#edit_cmb_controller').val());
	$('#action_txt').val($('#edit_txt_action').val());
	frm.submit();
}
function delete_controller(id) {
	var r = confirm("Do you want to delete this ?");
	if(r == true){
		var frm = document.main_form;
		$('#id').val(id);
		frm.submit();
	}
}
$(document).ready(function() {
	$('#add-controller').click(function(){
		jQuery( "#add-form" ).dialog({
			resizable: true,
			height:250,
			width: 500,
			modal: true,
			buttons:[{
				text: 'Thêm',
				click : function() {
					add_controller();
					}
				},{
				text: 'Hủy bỏ',
				click : function() { $(this).dialog("close"); }
			}]
		});
	});
	
	$('.edit_controller').click(function(){
		$('#edit_txt_name').val($(this).attr('controller_name'));
		$('#edit_txt_controller').val($(this).attr('controller'));
		$('#id').val($(this).attr('controller_id'));
		jQuery( "#edit-form" ).dialog({
			resizable: true,
			height:250,
			width: 500,
			modal: true,
			buttons:[{
				text: 'Sửa',
				click : function() {
					edit_controller();
				}
			},{
				text: 'Hủy bỏ',
				click : function() { $(this).dialog("close"); }
			}]
		});
	});

	$('#add-action').click(function(){
		jQuery( "#add-form" ).dialog({
			resizable: true,
			height:250,
			width: 500,
			modal: true,
			buttons:[{
				text: 'Thêm',
				click : function() {
					add_action();
				}
			},{
				text: 'Hủy bỏ',
				click : function() { $(this).dialog("close"); }
			}]
		});
	});
	
	$('.edit_action').click(function(){
		$('#edit_cmb_controller').val($(this).attr('controller_id'));
		$('#edit_txt_name').val($(this).attr('action_name'));
		$('#edit_txt_action').val($(this).attr('action'));
		$('#id').val($(this).attr('action_id'));
		jQuery( "#edit-form" ).dialog({
			resizable: true,
			height:250,
			width: 500,
			modal: true,
			buttons:[{
				text: 'Sửa',
				click : function() {
					edit_action();
				}
			},{
				text: 'Hủy bỏ',
				click : function() { $(this).dialog("close"); }
			}]
		});
	});
});